
;(function($,window) {

	var listPage = {

		config:{
			guideNode: $('#js_city_guide'),
			defCity : $('#js_defcity'),
			guideCity : $('.js_guide_city'),
			guideCityBox : $('.sitenav-city'),
			closeGuide : $('.js_close_guide')
		},

		init:function(){

			//图片懒加载
			$("img.lazy").lazyload({effect: "fadeIn", failure_limit:10});

			//图文互动效果
			this.productMove();

			//反馈链接
			this.comp();

			//城市引导
			this.cityGuide();

			//页面resize
			this.resize();
		},
		productMove:function(){
			var $provideLi = $('.js_boxHover'),
				_this = this;

			$provideLi.hover(function(){
				$(this).stop().animate({'margin-top':'-5px'},300).css("box-shadow","0 0 13px #999");
			},function(){
				$(this).stop().animate({'margin-top':'0px'},300).css("box-shadow","none");
			});
		},
		comp:function(){
			if($('#search-comp').length <= 0){
				return false;
			};

			$('#search-comp').on('click',function(){
				sidebar.openFeedbook();
			});
		},
		cityGuide:function(){
			var config = this.config;

			//cookie 有值 return;
			if(config.guideNode.length<=0 || this.getCookie('first_list')){
				return false;
			}
			//设置cookie
			this.setCookie('first_list','1');

			//关闭引导框
			function closeGuide(){
				if(config.guideNode.hasClass('show')){
					config.guideNode.removeClass('show').addClass('hide');
				}
			}

			config.guideCityBox.hover(function(){
				closeGuide();
			});

			config.closeGuide.on('click',function(){
				closeGuide();
			});

			this.resizeFun();

			config.guideCity.html(this.getCookie('city.name') || '上海');
			config.guideNode.removeClass('hide').addClass('show');

		},
		resize:function(){
			var _self = this;
			$(window).on('resize',_self.resizeFun);
		},
		resizeFun:function(){

			var	config = listPage.config,
				guideTop = config.defCity.offset().top,
				guideLeft = config.defCity.offset().left;

			config.guideNode.css({'top':guideTop+22,'left':guideLeft-10});
		},
		//Cookie Common Class
		getCookie:function(key) {
			var result = document.cookie.match(new RegExp("(^| )" + key + "=([^;]*)"));
			return result != null ? decodeURIComponent(result[2]) : null;
		},
		setCookie:function(key, value, expireDay) {
			if (expireDay) {
				var date = new Date();
				date.setTime(date.getTime() + expireDay * 24 * 3600 * 1000);
				document.cookie = key + "=" + encodeURIComponent(value) + ";path=/;expires=" + date.toGMTString();
			} else {
				document.cookie = key + "=" + encodeURIComponent(value) + ";path=/";
			}
		}
	};

	listPage.init();

	var priceRange = {
		_self:'',
		priceElm : $('#js_price_range'),
		fromPrice : $('#js_from_price'),
		toPrice : $('#js_to_Price'),
		priceBtn : $('.js_range_submit'),
		warning : function(element){
			element.css("border-color","red");
		},
		//重置颜色
		reset : function(){
			$("#js_from_price").css("border-color","#03a9f4");
			$("#js_to_Price").css("border-color","#03a9f4");
		},
		priceSubmit : function(){
			_self = priceRange;
			_self.priceBtn.click(function(){
				var fromPrice = parseInt(_self.fromPrice.val());
				var toPrice = parseInt(_self.toPrice.val());
				var bool = false;
				//判断输入的值是否是数值类型
				if(isNaN(fromPrice)){
	//						_self.warning($('#js_from_price'));
	//						bool = true;
					fromPrice = 0;
				}
				if(_self.toPrice.val().trim().length > 0 && isNaN(toPrice)){
					_self.warning($('#js_to_Price'));
					bool = true;
				}
				if(bool)
					return;
				//价格必须低到高
				if(fromPrice < 0 || fromPrice < 0 || (toPrice < fromPrice)){
					_self.warning($('#js_from_price'));
					_self.warning($('#js_to_Price'));
					return;
				}else{
					_self.reset();
				}
				var loc = window.location.href;
				//重新定义href
				if(loc.lastIndexOf(".html") > -1){
					loc = loc.substring(0,loc.lastIndexOf(".html")+".html".length);
				}
				if(isNaN(toPrice)){
					toPrice = "";
				}
				window.location.href = loc + "?minBarePrice=" + fromPrice + "&maxBarePrice=" + toPrice;
			});
		}
	};

	priceRange.priceSubmit();

})(jQuery,window);

